<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>提示词管理</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    
    body {
      font-family: Arial, sans-serif;
      background: #f5f5f5;
      margin: 0;
      padding: 0;
      height: 100vh;
      overflow: hidden;
    }
    
    .container {
      width: 100%;
      height: 100vh;
      background: white;
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }
    
    .header {
      background: #4285f4;
      color: white;
      padding: 15px 20px;
      text-align: center;
      flex-shrink: 0;
    }
    
    .header h1 {
      font-size: 20px;
      margin-bottom: 8px;
    }
    
    .stats {
      display: flex;
      justify-content: center;
      gap: 30px;
      margin-top: 8px;
    }
    
    .stat-item {
      text-align: center;
    }
    
    .stat-number {
      font-size: 18px;
      font-weight: bold;
    }
    
    .stat-label {
      font-size: 11px;
      opacity: 0.8;
    }
    
    .tabs-container {
      display: flex;
      flex-direction: column;
      gap: 10px;
    }
    
    .tabs {
      display: flex;
      gap: 5px;
      justify-content: center;
    }
    
    .tab-btn {
      padding: 6px 16px;
      border: none;
      border-radius: 20px;
      background: rgba(255, 255, 255, 0.2);
      color: white;
      font-size: 12px;
      cursor: pointer;
      transition: all 0.2s;
    }
    
    .tab-btn:hover {
      background: rgba(255, 255, 255, 0.3);
    }
    
    .tab-btn.active {
      background: rgba(255, 255, 255, 0.9);
      color: #4285f4;
      font-weight: 500;
    }
    
    .header-actions {
      display: flex;
      justify-content: center;
      gap: 10px;
      margin-top: 10px;
    }
    
    .action-btn {
      padding: 6px 12px;
      border: none;
      border-radius: 4px;
      font-size: 12px;
      cursor: pointer;
      transition: all 0.2s;
    }
    
    .backup-btn {
      background: #4caf50;
      color: white;
    }
    
    .backup-btn:hover {
      background: #45a049;
    }
    
    .restore-btn {
      background: #ff9800;
      color: white;
    }
    
    .restore-btn:hover {
      background: #e68900;
    }
    
    .export-btn {
      background: #2196f3;
      color: white;
    }
    
    .export-btn:hover {
      background: #1976d2;
    }
    
    .upload-btn {
      background: #9c27b0;
      color: white;
    }
    
    .upload-btn:hover {
      background: #7b1fa2;
    }
    
    .sync-btn {
      background: #00bcd4;
      color: white;
    }
    
    .sync-btn:hover {
      background: #0097a7;
    }
    
    .auto-sync-btn {
      background: #4caf50;
      color: white;
    }
    
    .auto-sync-btn:hover {
      background: #45a049;
    }
    
    .auto-sync-btn.disabled {
      background: #f44336;
    }
    
    .auto-sync-btn.disabled:hover {
      background: #d32f2f;
    }
    
    .stat-number.online {
      color: #4caf50;
    }
    
    .stat-number.offline {
      color: #f44336;
    }
    
    .stat-number.checking {
      color: #ff9800;
    }
    
    .stat-number.synced {
      color: #4caf50;
    }
    
    .stat-number.unsynced {
      color: #f44336;
    }
    
    .stat-number.unknown {
      color: #9e9e9e;
    }
    
    .search-container {
      padding: 20px 24px;
      background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
      border-bottom: 1px solid #e0e0e0;
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 20px;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    }
    
    .search-left {
      display: flex;
      gap: 10px;
      flex: 1;
    }
    
    .search-right {
      display: flex;
      align-items: center;
    }
    
    .search-btn {
      padding: 10px 20px;
      background: linear-gradient(135deg, #4285f4 0%, #34a853 100%);
      color: white;
      border: none;
      border-radius: 6px;
      cursor: pointer;
      font-size: 14px;
      font-weight: 500;
      transition: all 0.3s ease;
      box-shadow: 0 2px 4px rgba(66, 133, 244, 0.2);
      display: flex;
      align-items: center;
      gap: 6px;
    }
    
    .search-btn:hover {
      background: linear-gradient(135deg, #3367d6 0%, #2d8f47 100%);
      transform: translateY(-1px);
      box-shadow: 0 4px 8px rgba(66, 133, 244, 0.3);
    }
    
    .search-btn:active {
      transform: translateY(0);
      box-shadow: 0 2px 4px rgba(66, 133, 244, 0.2);
    }
    
    .search-btn:before {
      content: '🔍';
      font-size: 16px;
    }
    
    .tab-switch {
      display: flex;
      background: #e9ecef;
      border-radius: 6px;
      padding: 2px;
      gap: 2px;
    }
    
    .tab-switch-btn {
      padding: 8px 16px;
      border: none;
      background: transparent;
      color: #6c757d;
      cursor: pointer;
      border-radius: 4px;
      font-size: 14px;
      font-weight: 500;
      transition: all 0.2s;
    }
    
    .tab-switch-btn.active {
      background: white;
      color: #4285f4;
      box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    }
    
    .tab-switch-btn:hover:not(.active) {
      color: #495057;
    }
    
    .upload-hint {
      padding: 8px 20px;
      background: #f8f9fa;
      border-bottom: 1px solid #e0e0e0;
      text-align: center;
    }
    
    .hint-text {
      font-size: 12px;
      color: #6c757d;
      font-style: italic;
    }
    
    .search-input {
      flex: 1;
      padding: 12px 16px;
      border: 2px solid #e0e0e0;
      border-radius: 8px;
      font-size: 14px;
      transition: all 0.3s ease;
      background: white;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    }
    
    .search-input:focus {
      outline: none;
      border-color: #4285f4;
      box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.1), 0 4px 8px rgba(0, 0, 0, 0.1);
      transform: translateY(-1px);
    }
    
    .search-input::placeholder {
      color: #9e9e9e;
      font-style: italic;
    }
    
    .clear-search-btn {
      padding: 10px 16px;
      background: linear-gradient(135deg, #f44336 0%, #ff7043 100%);
      color: white;
      border: none;
      border-radius: 6px;
      cursor: pointer;
      font-size: 14px;
      font-weight: 500;
      transition: all 0.3s ease;
      box-shadow: 0 2px 4px rgba(244, 67, 54, 0.2);
      display: flex;
      align-items: center;
      gap: 6px;
    }
    
    .clear-search-btn:hover {
      background: linear-gradient(135deg, #d32f2f 0%, #ff5722 100%);
      transform: translateY(-1px);
      box-shadow: 0 4px 8px rgba(244, 67, 54, 0.3);
    }
    
    .clear-search-btn:active {
      transform: translateY(0);
      box-shadow: 0 2px 4px rgba(244, 67, 54, 0.2);
    }
    
    .clear-search-btn:before {
      content: '✕';
      font-size: 16px;
      font-weight: bold;
    }
    
    .edit-modal-content {
      max-width: 600px;
      width: 90%;
      max-height: 80vh;
      background: white;
      border-radius: 8px;
      display: flex;
      flex-direction: column;
    }
    
    .modal-header {
      padding: 20px;
      border-bottom: 1px solid #e0e0e0;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    
    .modal-header h3 {
      margin: 0;
      color: #333;
    }
    
    .modal-body {
      padding: 20px;
      flex: 1;
    }
    
    .edit-textarea {
      width: 100%;
      height: 300px;
      padding: 12px;
      border: 1px solid #ddd;
      border-radius: 4px;
      font-size: 14px;
      font-family: Arial, sans-serif;
      resize: vertical;
    }
    
    .edit-textarea:focus {
      outline: none;
      border-color: #4285f4;
      box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.2);
    }
    
    .modal-footer {
      padding: 20px;
      border-top: 1px solid #e0e0e0;
      display: flex;
      gap: 10px;
      justify-content: flex-end;
    }
    
    .save-btn {
      padding: 8px 16px;
      background: #4caf50;
      color: white;
      border: none;
      border-radius: 4px;
      cursor: pointer;
    }
    
    .save-btn:hover {
      background: #45a049;
    }
    
    .cancel-btn {
      padding: 8px 16px;
      background: #f44336;
      color: white;
      border: none;
      border-radius: 4px;
      cursor: pointer;
    }
    
    .cancel-btn:hover {
      background: #d32f2f;
    }
    
    .edit-btn {
      background: #ff9800;
      color: white;
      border: none;
      padding: 4px 8px;
      border-radius: 4px;
      font-size: 11px;
      cursor: pointer;
      white-space: nowrap;
      flex-shrink: 0;
      min-width: 40px;
    }
    
    .edit-btn:hover {
      background: #e68900;
    }
    
    .favorite-btn {
      background: transparent;
      border: 1px solid #ddd;
      padding: 4px 8px;
      border-radius: 4px;
      cursor: pointer;
      font-size: 14px;
      white-space: nowrap;
      flex-shrink: 0;
      transition: all 0.2s;
      min-width: 40px;
    }
    
    .favorite-btn:hover {
      background: #f8f9fa;
      border-color: #ff6b6b;
    }
    
    .favorite-btn.favorited {
      background: #ff6b6b;
      border-color: #ff6b6b;
      color: white;
    }
    
    .favorite-btn.favorited:hover {
      background: #ff5252;
      border-color: #ff5252;
    }
    
    .prompt-actions {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding-top: 10px;
      border-top: 1px solid #f0f0f0;
      flex-shrink: 0;
    }
    
    .prompt-actions-left {
      display: flex;
      gap: 4px;
      flex-wrap: wrap;
    }
    
    .prompt-actions-right {
      display: flex;
      gap: 4px;
      flex-wrap: wrap;
    }
    
    /* 竖屏模式优化 */
    @media (max-width: 768px) {
      .prompt-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
      }
      
      .prompt-actions-left,
      .prompt-actions-right {
        justify-content: center;
        width: 100%;
      }
      
      .prompt-text {
        font-size: 13px;
        line-height: 1.3;
      }
      
      .copy-btn,
      .edit-btn,
      .favorite-btn,
      .delete-btn {
        flex: 1;
        min-width: 60px;
        font-size: 10px;
        padding: 6px 4px;
      }
    }
    
    .prompt-time {
      font-size: 11px;
      color: #666;
      margin-bottom: 8px;
      opacity: 0.8;
    }
    
    .drag-over {
      background: rgba(66, 133, 244, 0.1) !important;
      border: 2px dashed #4285f4 !important;
    }
    
    .drag-over::before {
      content: "拖拽图片到这里上传";
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      background: rgba(66, 133, 244, 0.9);
      color: white;
      padding: 20px;
      border-radius: 8px;
      font-size: 16px;
      z-index: 1000;
      pointer-events: none;
    }
    
    .content {
      flex: 1;
      padding: 20px;
      overflow-y: auto;
      display: flex;
      flex-direction: column;
      transition: all 0.3s ease;
    }
    
    .content.drag-over {
      background: rgba(66, 133, 244, 0.1);
      border: 2px dashed #4285f4;
    }
    
    .prompts-grid {
      display: grid;
      /* 网格布局由JavaScript动态设置 */
      margin-bottom: 20px;
      flex: 1;
      overflow-y: auto;
    }
    
    .prompt-card {
      border: 1px solid #e0e0e0;
      border-radius: 8px;
      overflow: hidden;
      transition: transform 0.2s, box-shadow 0.2s;
      cursor: pointer;
      display: flex;
      flex-direction: column;
      min-height: 320px;
      max-height: 400px;
    }
    
    .prompt-card:hover {
      transform: translateY(-2px);
      box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    }
    
    .image-container {
      position: relative;
      width: 100%;
      height: 180px;
      background: #f8f9fa;
      overflow: hidden;
      display: flex;
      flex-shrink: 0;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
    }
    
    .prompt-image {
      width: 100%;
      height: 100%;
      object-fit: contain;
      cursor: pointer;
      display: block;
      background: #f8f9fa;
    }
    
    .image-placeholder {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      background: #f8f9fa;
      color: #6c757d;
      font-size: 14px;
      border: 2px dashed #dee2e6;
    }
    
    .prompt-content {
      padding: 15px;
      flex: 1;
      display: flex;
      flex-direction: column;
      min-height: 0; /* 允许flex子元素收缩 */
    }
    
    .prompt-text {
      font-size: 14px;
      line-height: 1.4;
      color: #333;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 1;
      -webkit-box-orient: vertical;
      cursor: pointer;
      margin-bottom: 10px;
      min-height: 1.4em; /* 确保至少显示一行 */
      flex-shrink: 1;
      word-break: break-word;
      white-space: nowrap;
    }
    
    .prompt-text:hover {
      color: #4285f4;
    }
    
    .prompt-actions {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 8px 0;
      border-top: 1px solid #f0f0f0;
      flex-shrink: 0;
      min-height: 36px;
      margin-top: auto;
      flex-wrap: wrap;
      gap: 4px;
    }
    
    .copy-btn {
      background: #4285f4;
      color: white;
      border: none;
      padding: 4px 8px;
      border-radius: 4px;
      cursor: pointer;
      font-size: 11px;
      white-space: nowrap;
      flex-shrink: 0;
      min-width: 40px;
    }
    
    .copy-btn:hover {
      background: #3367d6;
    }
    
    .delete-btn {
      background: #dc3545;
      color: white;
      border: none;
      padding: 4px 8px;
      border-radius: 4px;
      cursor: pointer;
      font-size: 11px;
      white-space: nowrap;
      flex-shrink: 0;
      min-width: 40px;
    }
    
    .delete-btn:hover {
      background: #c82333;
    }
    
    .pagination {
      display: flex;
      justify-content: center;
      align-items: center;
      gap: 10px;
      margin-top: auto;
      padding: 15px 0;
      border-top: 1px solid #e0e0e0;
      background: white;
      flex-shrink: 0;
    }
    
    .pagination button {
      padding: 8px 16px;
      border: 1px solid #ddd;
      background: white;
      cursor: pointer;
      border-radius: 4px;
    }
    
    .pagination button:hover:not(:disabled) {
      background: #f0f0f0;
    }
    
    .pagination button:disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }
    
    .pagination .current-page {
      background: #4285f4;
      color: white;
      border-color: #4285f4;
    }
    
    .pagination .page-input {
      width: 60px;
      padding: 6px 8px;
      border: 1px solid #ddd;
      border-radius: 4px;
      text-align: center;
      font-size: 14px;
    }
    
    .pagination .per-page-select {
      padding: 6px 8px;
      border: 1px solid #ddd;
      border-radius: 4px;
      background: white;
      font-size: 14px;
      cursor: pointer;
    }
    
    .pagination .per-page-select:hover {
      border-color: #4285f4;
    }
    
    .layout-info {
      font-size: 11px;
      color: #666;
      margin-left: 4px;
      font-style: italic;
    }
    
    .pagination span {
      font-size: 14px;
      color: #666;
    }
    
    .page-input {
      width: 60px;
      padding: 8px;
      border: 1px solid #ddd;
      border-radius: 4px;
      text-align: center;
    }
    
    .empty-state {
      text-align: center;
      padding: 60px 20px;
      color: #666;
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
    }
    
    .empty-state h3 {
      margin-bottom: 10px;
      color: #333;
    }
    
    /* 全屏图片模态框 */
    .modal {
      display: none;
      position: fixed;
      z-index: 1000;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      background-color: rgba(0,0,0,0.9);
    }
    
    .modal-content {
      position: relative;
      margin: auto;
      padding: 0;
      width: 90%;
      max-width: 1200px;
      top: 50%;
      transform: translateY(-50%);
    }
    
    .modal-image {
      width: 100%;
      height: auto;
      max-height: 90vh;
      object-fit: contain;
    }
    
    .modal-close {
      position: absolute;
      top: 15px;
      right: 35px;
      color: #f1f1f1;
      font-size: 40px;
      font-weight: bold;
      cursor: pointer;
    }
    
    .modal-close:hover {
      color: #bbb;
    }
    
    .loading {
      text-align: center;
      padding: 40px;
      color: #666;
      flex: 1;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  </style>
</head>
<body>
  <div class="container">
    <div class="header">
      <h1>提示词管理</h1>
      <div class="header-actions">
        <button class="action-btn upload-btn" id="uploadBtn">上传图片</button>
        <button class="action-btn export-btn" id="exportBtn">导出Excel</button>
      </div>
    </div>
    
    <div class="content">
      <div class="search-container">
        <div class="search-left">
          <input type="text" id="searchInput" placeholder="搜索提示词..." class="search-input">
          <button id="searchBtn" class="search-btn">搜索</button>
          <button id="clearSearchBtn" class="clear-search-btn" style="display: none;">清除</button>
        </div>
        <div class="search-right">
          <div class="tab-switch">
            <button class="tab-switch-btn active" id="allTab">全部</button>
            <button class="tab-switch-btn" id="favoriteTab">收藏</button>
          </div>
        </div>
      </div>
      <div class="upload-hint">
        <span class="hint-text">💡 支持拖拽图片、网络图片或 Ctrl+V 粘贴图片</span>
      </div>
      <div id="loading" class="loading">加载中...</div>
      <div id="promptsContainer" class="prompts-grid" style="display: none;"></div>
      <div id="emptyState" class="empty-state" style="display: none;">
        <h3>暂无提示词数据</h3>
        <p>请先使用"爬取提示词"功能添加数据</p>
      </div>
      <div id="pagination" class="pagination" style="display: none;"></div>
    </div>
  </div>
  
  <!-- 全屏图片模态框 -->
  <div id="imageModal" class="modal">
    <span class="modal-close" id="modalClose">&times;</span>
    <div class="modal-content">
      <img id="modalImage" class="modal-image" src="" alt="">
    </div>
  </div>

  <!-- 编辑提示词模态框 -->
  <div id="editModal" class="modal">
    <div class="modal-content edit-modal-content">
      <div class="modal-header">
        <h3>编辑提示词</h3>
        <span class="modal-close" id="editModalClose">&times;</span>
      </div>
      <div class="modal-body">
        <textarea id="editPromptText" class="edit-textarea" placeholder="请输入提示词内容..."></textarea>
      </div>
      <div class="modal-footer">
        <button id="saveEditBtn" class="save-btn">保存</button>
        <button id="cancelEditBtn" class="cancel-btn">取消</button>
      </div>
    </div>
  </div>

  <!-- 隐藏的文件输入 -->
  <input type="file" id="fileInput" accept="image/*" multiple style="display: none;">
  
  <script src="config.js"></script>
  <script src="manage.js"></script>
</body>
</html>
